<?php
/**
 * Authenticate logic for admin area
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo App überprüfung gegen Missbrauch einbauen Zeile 40
 */

class Rockitbos_WebController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        $this->_helper->layout->disableLayout();
    }
    /**
     * Login logic
     *
     * @return void
     */
    public function indexAction()
    {
        try {
        $auth = Zend_Auth::getInstance();

        if ($this->getRequest()->set == 'logout') {
            // log out
            $auth->clearIdentity();
            // redirect to login form
            $this->_redirect('/rockitbos');
        } else if ($auth->hasIdentity()) {

            $app = $this->_request->app;
            $tab = $this->_request->tab;            
            
            if (!empty($app)) {

                $layout = Zend_Layout::getMvcInstance();
                $layout->setLayoutPath(
                    'application/modules/rockitbos/views/scripts');
                $layout->setLayout('app');

                if(empty($tab)) {
                    $tab = 'app';
                }

                $this->_forward('index', $tab, $app);

                $front = Zend_Controller_Front::getInstance();
                $front->registerPlugin(new App_Plugin_Acl);
            } else {
                $this->_forward('index', 'dashboard', 'dashboard');
            }
        } else {
            // show login form
            $this->_forward('index', 'login', 'login');
        }
        } catch (Exception $e) {

            $this->_forward(
                'error',
                null,
                null,
                array('errorMessage' => $e->getMessage())
            );
        }
    }
    /**
     * Error output
     *
     * @return void
     */
    public function errorAction() {

        $this->setCss('error');
        $this->view->errorMessage = $this->_request->errorMessage;
    }
    protected function setCss($file) {

        $this->view
             ->headLink()
             ->appendStylesheet(
                 DIRECTORY_SEPARATOR . 'rockitbos' .
                 DIRECTORY_SEPARATOR . 'css' .
                 DIRECTORY_SEPARATOR . $file . ".css"
               );
    }
}